#include "blockQueue.hpp"

class Task
{
public:
    Task() {}

    Task(int x, int y, char op)
        : _x(x), _y(y), _op(op), _result(0), _codeRet(0)
    {
    }

    // 执行任务
    void operator()()
    {
        switch (_op)
        {
        case '+':
            _result = _x + _y;
            break;
        case '-':
            _result = _x - _y;
            break;
        case '/':
        {
            if (_y == 0)
                _codeRet = -1;
            else
                _result = _x / _y;
        }
        break;
        case '*':
            _result = _x * _y;
            break;
        case '%':
        {
            if (_y == 0)
                _codeRet = -2;
            else
                _result = _x % _y;
        }
        break;

        default:
            std::cout << "没有这样的运算符!" << std::endl;
            break;
        }
    }

    std::string formatArg()
    {
        return std::to_string(_x) + _op + std::to_string(_y) + "=";
    }

    std::string formatRes()
    {
        return std::to_string(_result) + "(" + std::to_string(_codeRet) + ")";
    }

    ~Task() {}

private:
    int _x;
    int _y;
    char _op; // 运算符

    int _result;  // 运算结果
    int _codeRet; // 运算成功与否
};